Single statement if block - braces or no? [on hold]
Posted
by
Zannjaminderson
on Programmers
See other posts from Programmers
or by Zannjaminderson
Published on 2010-11-03T14:43:35Z
Indexed on
2014/06/01
3:49 UTC
Read the original article
Hit count: 94
coding-style
Which is better/more generally accepted?
This:
if(condition)
{
statement;
}
Or:
if(condition)
statement;
I tend to prefer the first one, because I think it makes it easier to tell what actually belongs in the if block, it saves others from adding the braces later (or creating a bug by forgetting to), and it makes all your if statements uniform instead of some with braces and some without. The second one, however, is still syntactically correct and definitely more compact. I'm curious to see which is more generally preferred by others though.
© Programmers or respective owner